package com.nav.brainfuckeditor.editors;

import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;

public class SingleCharRule implements IPredicateRule {
	private char c;
	private IToken token;
	public SingleCharRule(char c, IToken token) {
		this.c = c;
		this.token = token;
	}
	@Override
	public IToken evaluate(ICharacterScanner scanner) {
		char c = (char)scanner.read();
		if(c == this.c)
			return token;
		scanner.unread();
		return Token.UNDEFINED;
	}

	@Override
	public IToken evaluate(ICharacterScanner scanner, boolean resume) {
		char c = (char)scanner.read();
		if(c == this.c)
			return token;
		scanner.unread();
		return Token.UNDEFINED;
	}

	@Override
	public IToken getSuccessToken() {
		return token;
	}
}
